<?php
class Article_model extends MY_Model{
	public $_table = 'tbl_article';
	protected $_gallery_path = "";
    protected $_gallery_url = "";
	
	public $belongs_to = array( 'catalog' => array( 'primary_key' => 'catalog_id' ) );
    
	public function __construct(){
        parent::__construct();
        $this->_gallery_url = base_url()."upload/images";
        $this->_gallery_path = realpath(APPPATH. "../public/images");
    }
    
	public function do_upload(){
        $config = array('upload_path'   => ".upload/images",
                        'allowed_types' => 'gif|jpg|png',
                        'max_size'      => '2000');
        $this->load->library("upload",$config);
        if(!$this->upload->do_upload()){
            $error = array('error' => $this->upload->display_errors());
            print_r($error);
        }else{
//            $image_data = $this->upload->data();    
        }
        
//        $config = array("source_image" => $image_data['full_path'],
//                        "new_image" => $this->_gallery_path . "/thumbs",
//                        "maintain_ration" => true,
//                        "width" => '150',
//                        "height" => "100");
//        $this->load->library("image_lib",$config);
//        $this->image_lib->resize();
    }
    
    public function get_images(){
        $file = scandir($this->_gallery_path);
        $file = array_diff($file, array('.', '..', 'thumbs'));
        
        
        $images = array();
        foreach($file as $img){
            $images[] = array("url"        => $this->_gallery_url . $img,
                              "thumb_url" => $this->_gallery_url . "thumbs/" . $img);    
        }
        return $images;
    }
}
?>